/**
 * https://leetcode.cn/submissions/detail/558812844/
 * 209. 长度最小的子数组
 * medium 黄伟杰 2024.8.26
 * 滑动窗口
 */

#include <bits/stdc++.h>
using namespace std;

class Solution
{
public:
    int minSubArrayLen(int target, vector<int> &nums)
    {
        int i = 0, j = 0, sum = 0, cnt = 0, ans = 10e8;
        for (; j < nums.size(); j++)
        {
            sum += nums[j];
            while (sum >= target)
            {
                ans = min(ans, j - i + 1);
                sum -= nums[i];
                i++;
            }
        }
        if (ans == 10e8)
            return 0;
        return ans;
    }
};